<?php
  session_start();
  header("content-type=textml; charset=utf-8");  //设置字符集
  require("config.php");  //包含数据库连接文件
  $username  = $_POST['username']; //获取用户姓名
  $password  = $_POST['password'];  //获取密码

  //判断用户名密码是否为空
  if($username== NULL || $password== NULL)
  {
	 echo "<script>alert('用户名密码不允许为空！');window.location.href='signin.html';</script>";
	 exit;
  }

    $sql="select * from users where u_name='$username'";
	$re = mysql_query($sql);
	$user = mysql_fetch_array($re);
	if($username == $user['u_name'] && $password == $user['u_pwd']){
		 setcookie("u_name",$user['u_name'],time()+3600);
		 setcookie("u_id",$user['u_id'],time()+3600);
		echo "<script>alert('用户登陆成功！');window.location.href='add.html';</script>";

	}
	else
	{
		echo "<script>alert('登陆失败！用户名或密码不正确，请核对后重新输入');window.location.href='signin.html';</script>";

	}
   mysql_close($con);
 ?>